
package com.idealighter.game.dictionary.dic;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.dictionary.core.DictionaryTable;
import com.idealighter.game.dictionary.domain.RoomCardMustNiuNiuFeeDomain;
import com.idealighter.game.dictionary.mapper.RoomCardMustNiuNiuFeeMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Singleton
public class RoomCardMustNiuNiuFeeDic implements DictionaryTable<RoomCardMustNiuNiuFeeDomain> {

  private RoomCardMustNiuNiuFeeMapper mapper;
  private List<RoomCardMustNiuNiuFeeDomain> list;
  private Map<Integer, RoomCardMustNiuNiuFeeDomain> map;

  @Inject
  public RoomCardMustNiuNiuFeeDic(RoomCardMustNiuNiuFeeMapper mapper) {
    this.mapper = mapper;
    load();
  }

  @Override
  public List<RoomCardMustNiuNiuFeeDomain> list() {
    return list;
  }

  @Override
  public Map<Integer, RoomCardMustNiuNiuFeeDomain> map() {

    return map;
  }

  @Override
  public void load() {
    this.list = mapper.selectAll();
    Map<Integer, RoomCardMustNiuNiuFeeDomain> map = new HashMap<>();
    list.forEach(val -> map.put(val.getId(), val));
    this.map = map;
  }

  @Override
  public RoomCardMustNiuNiuFeeDomain get(int id) {
    return map.get(id);
  }

  public List<RoomCardMustNiuNiuFeeDomain> fee(byte type) {
    List<RoomCardMustNiuNiuFeeDomain> resultList = new ArrayList<>();
    for (RoomCardMustNiuNiuFeeDomain item : list) {
      if (item.getType() == type) {
        resultList.add(item);
      }
    }
    return resultList;
  }
}
